package com.xiao.sulinguser.controller;

import com.alibaba.nacos.common.utils.StringUtils;
import com.xiao.sulingpublic.utils.R;
import com.xiao.sulinguser.myenum.RedisEnum;
import com.xiao.sulinguser.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 1322127758@qq.com
 * @date: 2022/3/13 10:05
 * @作用: 阿里的短信功能
 */
@RestController
@RequestMapping("/sms")
public class SmsController {
    @Autowired
    private SmsService smsService;

    /**
     * 发送验证码
     * @param mobile 给这个手机号发送
     * @return
     */
    @RequestMapping("/sendcode")
    public R sendCode(@RequestParam(value = "mobile",required = false) String mobile){

        RedisEnum redisEnum = null;
        if(!StringUtils.isEmpty(mobile)){
            //返回状态码
            redisEnum = smsService.sendCode(mobile);
        }

        String data = "发送验证码失败";
        if(null != redisEnum){
            data = redisEnum.getMess();
        }
        return R.ok().put("data",data);
    }
}
